<%@page contentType="text/html; UTF-8" pageEncoding="UTF-8" isELIgnored="false" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>用户登录</title>
    <link rel="stylesheet" href="statics/css/bootstrap.min.css">
    <link rel="stylesheet" href="statics/css/reg.css">
    <script src="statics/js/jquery-1.8.3.min.js"></script>
</head>
<body >
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-6 offset-sm-3">
            <h1 class="text-center">用户登录</h1>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-6 offset-sm-3">
            <form id="inputform">
                <div class="form-group">
                    <label for="name">用户名:</label>
                    <input type="text" class="form-control" id="name" placeholder="用户名" >
                </div>
                <div class="form-group">
                    <label for="pwd">密码:</label>
                    <input type="password" class="form-control" id="pwd"  placeholder="密码" >
                </div>
                <div class="form-group">
                    <label for="pwd">验证码:</label>
                    <div>
                        <input type="text" id="test" class="form-control" placeholder="请输入验证码" style="width: 60%;float: left">
                        <img id="image" class="img-fluid" src="${pageContext.request.contextPath}/user/getImage" style="float: right;width: 25%;height: 38px;" alt="">
                    </div>
                </div>
                <div style="margin-top: 50px;clear:both;">
                    <button type="submit"  id="login" class="btn btn-primary" style="float: left;width: 47%;">登陆</button>
                    <a href="register.jsp" type="submit" id="register" class="btn btn btn-success" style="width: 47%;float: right;">注册</a>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
</html>
<script>
    $(function (){
        $("#login").click(function(){
            $.post("${pageContext.request.contentType}/user/login",
                {
                    name:$("#name").val(),
                    password:$("#pwd").val(),
                    code:$("#test").val()
                },
                function(data,status){
                    if (data.status){
                        alert(data.msg+",点击跳转主页面");
                        location.href = "${pageContext.request.contextPath}/back/index.jsp";
                    }else {
                        alert(data.msg);
                    }
                });
        });
    <%--    $(function (){--%>
    <%--        $("#login").click(function(){--%>
    <%--            var model = [];--%>
    <%--            model.push($("#name").val(),$("#pwd").val(),$("#test").val());--%>
    <%--            $.ajax({--%>
    <%--                url: '${pageContext.request.contentType}/user/login',--%>
    <%--                data: JSON.stringify(model),--%>
    <%--                type: 'POST',--%>
    <%--                contentType: 'application/json;charset=utf-8',--%>
    <%--                async: true,//异步--%>
    <%--                success: function (data)--%>
    <%--                {--%>
    <%--                    if (data.status){--%>
    <%--                        alert(data.msg+",点击跳转主页面");--%>
    <%--                        location.href = "${pageContext.request.contextPath}/back/index.jsp";--%>
    <%--                    }else {--%>
    <%--                        alert(data.msg);--%>
    <%--                    }--%>
    <%--                }--%>
    <%--            });--%>
    <%--        });--%>
        <%--$("#login").click(function (){--%>
        <%--    $.post("${pageContext.request.contentType}/user/login",$("#inputform").serialize(),function (res){--%>
        <%--        if(res.status){--%>
        <%--            alert(res.msg+",点击跳转主页面");--%>
        <%--            location.href="${pageContext.request.contextPath}/back/index.jsp"--%>
        <%--        }else{--%>
        <%--            alert(res.msg);--%>
        <%--        }--%>

        <%--    });--%>
        <%--})--%>

        $("#image").click(function (){
            $(this).attr("src","${pageContext.request.contextPath}/user/getImage?id="+Math.random());
        })
    })
</script>
